from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import MinValueValidator, MaxValueValidator


class CustomUser(AbstractUser):
    """自定义用户模型，扩展默认User模型"""
    phone = models.CharField('手机号', max_length=11, blank=True, null=True)
    avatar = models.ImageField('头像', upload_to='avatars/', blank=True, null=True)
    birth_date = models.DateField('出生日期', blank=True, null=True)
    bio = models.TextField('个人简介', max_length=500, blank=True)
    is_vip = models.BooleanField('VIP用户', default=False)
    vip_level = models.IntegerField(
        'VIP等级',
        default=0,
        validators=[MinValueValidator(0), MaxValueValidator(10)]
    )
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = '用户管理'
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.username} ({'VIP' if self.is_vip else '普通'})"
